<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI聊天组件示例</title>
    <style>
        body {
            margin: 0;
            padding: 20px;
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            background-color: #f5f5f5;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }

        .header {
            text-align: center;
            margin-bottom: 40px;
        }

        .header h1 {
            color: #333;
            margin-bottom: 10px;
        }

        .header p {
            color: #666;
            font-size: 1.1em;
        }

        .demo-section {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 20px;
            margin-bottom: 40px;
        }

        .controls {
            background: white;
            padding: 20px;
            border-radius: 12px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        }

        .control-group {
            margin-bottom: 20px;
        }

        .control-group label {
            display: block;
            margin-bottom: 8px;
            color: #333;
            font-weight: 500;
        }

        .control-group input,
        .control-group select {
            width: 100%;
            padding: 8px 12px;
            border: 1px solid #ddd;
            border-radius: 6px;
            font-size: 14px;
        }

        .control-group input:focus,
        .control-group select:focus {
            outline: none;
            border-color: #4f46e5;
        }

        #chat-container {
            min-height: 600px;
            background: white;
            border-radius: 12px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
            padding: 20px;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>AI聊天组件示例</h1>
            <p>这个示例展示了AI聊天组件的基本用法和自定义配置选项</p>
        </div>

        <div class="demo-section">
            <div class="controls">
                <div class="control-group">
                    <label for="apiKey">API密钥</label>
                    <input type="password" id="apiKey" value="your-api-key" />
                </div>

                <div class="control-group">
                    <label for="theme">主题</label>
                    <select id="theme">
                        <option value="light">浅色</option>
                        <option value="dark">深色</option>
                    </select>
                </div>

                <div class="control-group">
                    <label for="systemPrompt">系统提示语</label>
                    <input type="text" id="systemPrompt" value="你是AI助手，负责回答用户的问题。请提供专业、友好的回答。" />
                </div>

                <div class="control-group">
                    <label for="welcomeMessage">欢迎消息</label>
                    <input type="text" id="welcomeMessage" value="您好！我是AI助手，很高兴为您服务。请问有什么可以帮助您的吗？" />
                </div>

                <div class="control-group">
                    <label for="placeholder">输入框占位文本</label>
                    <input type="text" id="placeholder" value="请输入您的问题..." />
                </div>
            </div>

            <div id="chat-container"></div>
        </div>
    </div>

    <script type="module">
        import { AIChatWidget } from '../dist/index.js';

        // 获取配置元素
        const apiKeyInput = document.getElementById('apiKey');
        const themeSelect = document.getElementById('theme');
        const systemPromptInput = document.getElementById('systemPrompt');
        const welcomeMessageInput = document.getElementById('welcomeMessage');
        const placeholderInput = document.getElementById('placeholder');

        // 创建聊天组件实例
        function initializeChatWidget() {
            const config = {
                apiKey: apiKeyInput.value,
                theme: themeSelect.value,
                systemPrompt: systemPromptInput.value,
                welcomeMessage: welcomeMessageInput.value,
                placeholder: placeholderInput.value
            };

            // 清空容器
            const container = document.getElementById('chat-container');
            container.innerHTML = '';

            // 创建新实例
            new AIChatWidget('chat-container', config);
        }

        // 绑定配置更改事件
        [apiKeyInput, themeSelect, systemPromptInput, welcomeMessageInput, placeholderInput].forEach(element => {
            element.addEventListener('change', initializeChatWidget);
        });

        // 初始化聊天组件
        initializeChatWidget();
    </script>
</body>
</html>